package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserService;
import com.ruoyi.system.service.IUserServiceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户开通服务记录Controller
 * 
 * @author Jack
 * @date 2025-07-02
 */
@Controller
@RequestMapping("/system/service")
public class UserServiceController extends BaseController
{
    private String prefix = "system/service";

    @Autowired
    private IUserServiceService userServiceService;

    @RequiresPermissions("system:service:view")
    @GetMapping()
    public String service()
    {
        return prefix + "/service";
    }

    /**
     * 查询用户开通服务记录列表
     */
    @RequiresPermissions("system:service:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserService userService)
    {
        startPage();
        List<UserService> list = userServiceService.selectUserServiceList(userService);
        return getDataTable(list);
    }

    /**
     * 导出用户开通服务记录列表
     */
    @RequiresPermissions("system:service:export")
    @Log(title = "用户开通服务记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserService userService)
    {
        List<UserService> list = userServiceService.selectUserServiceList(userService);
        ExcelUtil<UserService> util = new ExcelUtil<UserService>(UserService.class);
        return util.exportExcel(list, "用户开通服务记录数据");
    }

    /**
     * 新增用户开通服务记录
     */
    @RequiresPermissions("system:service:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户开通服务记录
     */
    @RequiresPermissions("system:service:add")
    @Log(title = "用户开通服务记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserService userService)
    {
        return toAjax(userServiceService.insertUserService(userService));
    }

    /**
     * 修改用户开通服务记录
     */
    @RequiresPermissions("system:service:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserService userService = userServiceService.selectUserServiceById(id);
        mmap.put("userService", userService);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户开通服务记录
     */
    @RequiresPermissions("system:service:edit")
    @Log(title = "用户开通服务记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserService userService)
    {
        return toAjax(userServiceService.updateUserService(userService));
    }

    /**
     * 删除用户开通服务记录
     */
    @RequiresPermissions("system:service:remove")
    @Log(title = "用户开通服务记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userServiceService.deleteUserServiceByIds(ids));
    }
}
